<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{
        margin: 0;
        padding: 0;
    }
    #box{
        width: 100px;
        height: 100px;
        background: pink;
        /* position: absolute; */
        left: 100px;
        top:50px;
        
    }
    </style>
</head>
<body>
    <input type="button" value="按钮" id="btn">
    <div id="box"></div> 
    <script>
        var box = document.getElementById('box'); 
        function getStyle(element,attr){
            if(window.getComputedStyle){
                return window.getComputedStyle(element,null)[attr];
            }else{
                return element.currentStyle[attr];
            }
        }
        document.getElementById('btn').onclick=function(){
            // console.log(box.offsetLeft)
            console.log(getStyle(box,'top'));   //50px，是一个字符串类型
        }
    </script>
</body>
</html>